﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="reg.aspx.cs" Inherits="reg" %>
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript" src="js/jquery-1.6.1.js"></script>
    <script type="text/javascript" src="js/jquery.query.get.js"></script>
    <script type="text/javascript">
    $(function(){
          jQuery.getScript("http://fw.qq.com/ipaddress",function(){$("#ip").val(IPData[0]);});
          function UserAdd()
          {
            var name=$("#username").val();
            var psd=$("#passwordtwo").val();
            var ip=$("#ip").val();
            var an=$("#answer").val();
            var question=$("#list").find("option:selected").attr("value");
            
            $.ajax({
                    async:true,
                    url:'API/A_Userreg.aspx',
                    type:'POST',
                    data:{
                          edit:'add',
                          i:ip,
                          u:name,
                          p:psd,
                          a:an,
                          q:question,
                          
                    },
                    dataType: 'json',
                    success:function(data)
                    {
                        if(data.err=="true"){
                                     var acturl="<a href=\"API/A_Userreg.aspx?edit=act&id="+data.id+"&key="+data.key+"\" target=\"_blank\">激活</a>";
                                     $("#activate").text("");
                                     $("#activate").append(acturl);
                        }else{
                                     $("#activate").text("");
                                     alert("NO");
                        }
                    }
            });
          }
          function Userlogon()
          {
            var name=$("#user").val();
            var pwd=$("#pwd").val();
            var ip=$("#ip").val();
            $.ajax({
                    async:false,
                    url:'API/A_Userreg.aspx',
                    type:'POST',
                    data:{
                          edit:'logon',
                          n:name,
                          p:pwd,
                          i:ip,
                    },
                    dataType:'json',
                    success:function(data)
                    {
                       if(data.err=="0")
                       {
                         alert("无此用户!");
                       }
                       else if(data.err=="1")
                       {
                         alert("先激活!");
                       }
                       else if(data.err=="2")
                       {
                         alert("密码错误!");
                       }
                       else if(data.err=="OK")
                       {
                         window.location="user/userinformation.aspx";
                       }
                    }
            });
          }
          function QuestionList()
          {
            $.ajax({
                    async:false,
                    url:'API/A_Userreg.aspx',
                    type:'POST',
                    data:{
                          edit:'list',
                    },
                    success:function(msg)
                    {
                      $("#list").text("");
                      $("#list").append(msg);
                      $("#safelist").text("");
                      $("#safelist").append(msg);
                    }
            });
          }
          function CheckName()
          {
              var name=$("#username").val();
              $.ajax({
                      async:false,
                      url:'API/A_Userreg.aspx',
                      type:'POST',
                      data:{
                            edit:'check',
                            u:name,
                      },
                      success:function(msg)
                      {
                        alert(msg);
                      }
              });
          }
          function test()
          {
            $.ajax({
                    async:false,
                    url:'API/A_Userreg.aspx',
                    type:'POST',
                    data:{edit:'test'},
                    success:function(msg)
                    {
                       alert(msg);
                    }
            });
          }
          function JumpSetPass(username,code,key)
          {
             jQuery.post('setpassword.aspx',{u:username,c:code,k:key});
          }
          function SelectPassword()
          {
             var username=$("#safeuser").val();
             var question=$("#safelist").find("option:selected").attr("value");
             var answer=$("#safeanswer").val();
             $.ajax({
                     async:false,
                     url:'API/A_Passsafe.aspx',
                     type:'POST',
                     data:{
                           edit:'check',
                           username:username,
                           q:question,
                           a:answer
                     },
                     dataType:'json',
                     success:function(data)
                     {
                        if(data.err=="true")
                        {
                        JumpSetPass(username,data.code,data.key);
                        window.location="setpassword.aspx?name="+username+"&code="+data.code+"&key="+data.key;
                        }
                        else
                        {
                          if(data.err=="0")
                          {
                            alert("问题回答错误！");
                          }
                          if(data.err=="1")
                          {
                            alert("不存在此用户！");
                          }
                        }
                     }
             });
          }
          
          $("#OK").click(function(){
                     UserAdd();
          });
          $("#logon").click(function(){
                     Userlogon();
          });
          $(document).ready(function(){
                     QuestionList();
          });
          $("#check").click(function(){
                     CheckName();
          });
          $("#test").click(function(){
                     test();
          });
          $("#find").click(function(){
                     SelectPassword();
          });
          $("#activate").text("");
    })
    </script>
</head>
<body>
    <skm:form id="form1" runat="server" method="post">
    <div>
    用户名：<input type="text" id="username" /><input type="button" value="检测用户名是否可用" id="check" /><br />
    密码：<input type="text" id="passwordone" /><br />
    确认密码：<input type="text" id="passwordtwo" /><br />
    IP地址：<input type="text" id="ip" readonly="readonly" /><br />
    密码保护：<select id="list"></select><br />
    密保答案：<input type="text" id="answer" /><br />
    <input type="button" id="OK" value="OK" /><input type="button" id="NO" value="NO" />
    </div>
    <div id="activate"></div>
    <div>
    用户名：<input type="text" id="user" /><br />
    密码：<input type="text" id="pwd" /><br />
    <input type="button" id="logon" value="登录" />
    <input type="button" id="test" value="测试" />
    </div>
    <div>
    <p>找回密码</p>
    用户名：<input type="text" id="safeuser" /><br />
    密码保护：<select id="safelist"></select><br />
    密保答案：<input type="text" id="safeanswer" /><br />
    <input type="button" value="找回密码" id="find" />
    </div>
    </skm:form>
</body>
</html>
